package com.kungfuhacking.wristbandpro.net;

import com.kungfuhacking.wristbandpro.base.bean.HttpListResult;
import com.kungfuhacking.wristbandpro.utils.Constant;

import java.util.List;

import io.reactivex.Observer;

/**
 * Created by Aaron on 17/4/21.
 */

public abstract class BaseListObserver<T> implements Observer<HttpListResult<T>> {

    @Override
    public void onNext(HttpListResult<T> value) {

        //网络返回的code不等于0,调用error
        if (value.getCode() == Constant.ERR0R_RELOGIN)
//            onReLogin();
            onReLogin(value.getCode_msg());
        else if (value.getCode() == 0)
            onHandleSuccess(value.getData());
        else
            onHandleError(value.getCode_msg());

    }

    @Override
    public void onError(Throwable e) {
        onHandleError("网络错误 : " + e.getMessage());
    }

    @Override
    public void onComplete() {
    }

    public abstract void onHandleSuccess(List<T> t);

    public abstract void onHandleError(String message);

//    public abstract void onReLogin();
    public abstract void onReLogin(String message);

}